package com.javaxiaobang.thread;

import com.alibaba.ttl.TransmittableThreadLocal;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 功    能：
 * 作    者：tianqiang
 * 时    间：2019/11/16
 */
public class ThreadLocalManager {

    private final static AtomicLong counter = new AtomicLong(1);

    private final static ThreadLocal threadLocal = new TransmittableThreadLocal();

    public static Long getCounter() {
        return counter.get();
    }


    public static void setCounter() {
        counter.incrementAndGet();
    }


    public static void reset() {
        threadLocal.remove();
        counter.set(1L);
    }

    public static void setName() {
        Long number = counter.incrementAndGet();
        threadLocal.set("线程" + number);
    }

    public static Object getName() {
        return threadLocal.get();
    }

}
